﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Jogo_Grupo2.Elementos
{
    class Monstro:Objeto2D
    {
        float timer = 0;
        float intervalo = 180f;
        int curframe = 0;
        int spriteWidth;
        int spriteHeight;
        Rectangle spriteRect;
        SpriteEffects invertido = SpriteEffects.FlipHorizontally;

        public int vida;
        public bool morreu;
        int ataque;


        public Monstro(Texture2D textura, Vector2 posicao, SpriteEffects spriteEffects)
            : base(textura, posicao)
        {
            vida = 3;

            spriteWidth = textura.Width / 6;
            spriteHeight = textura.Height;
            spriteRect = new Rectangle(curframe * spriteWidth, curframe * spriteHeight, spriteWidth, spriteHeight);
                
        }


        public void perderVida(int dano)
        {
            vida -= dano;

            if (vida <= 0)
            {
                vida = 0;
                morreu = true;
            }
        }

        public float AtaqueInimigo()
        {

            return 0.10f;

        }

        public override void Update(GameTime gameTime)
        {
            timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (curframe >= 5)
                curframe = 0;
            if (timer >= intervalo)
            {
                timer = 0;
                curframe++;
            }
            spriteRect.X = curframe * spriteWidth;
            this.position.X -= 1;


        
            base.Update(gameTime);

        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, new Rectangle((int)position.X, (int)position.Y, spriteWidth, spriteHeight), spriteRect, Color.White, 0, Vector2.Zero, invertido, 0);

        }



    }
}
